#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <signal.h>

void fun(int sig)
{
    printf("sig == %d\n", sig);
}

int main()
{
    signal(SIGPIPE, fun);
    int fd;
    char buff[128] = {0};

    mkfifo("fifo", 0777);
    fd = open("fifo", O_WRONLY);
    //assert(fd == -1);
    printf("fd = %d\n", fd);

    while (1) {
        printf("input:\n");
        fgets(buff, 128, stdin);
        write(fd, buff, strlen(buff));

        if (strncmp(buff, "end", 3) == 0) {
            break;
        }
    }

    close(fd);
    exit(0);
}